awk '# lookup -- reads local glossary file and prompts user for query

#0
BEGIN { FS = "\t"; OFS = "\t"
	# prompt user
	printf("Enter a glossary term: ")
} 

#1 read local file named glossary
FILENAME == "glossary" {
	# load each glossary entry into an array
	entry[$1] = $2
	next
} 

#2 scan for command to exit program
$0 ~ /^(quit|[qQ]|exit|[Xx])$/ { exit }

#3 process any non-empty line 
$0 != "" {
	if ( $0 in entry ) {
		# it is there, print definition
		print entry[$0]
	} else
		print $0 " not found"
}

#4 prompt user again for another term
{
	printf("Enter another glossary term (q to quit): ")
}' glossary -
